import { Injectable } from '@nestjs/common';
import { beanCopyArray, addTimeFields } from 'src/utils';
import { Response } from 'src/utils/response';
import { SiteRepository } from './site.repository';
import { SiteDataVO } from './vo/site-data.vo';

@Injectable()
export class SiteService {
  constructor(private readonly siteRepository: SiteRepository) {}

  async querySiteListService() {
    try {
      const dataList = await this.siteRepository.querySiteListRepository();
      const VO = new SiteDataVO();
      const result = beanCopyArray<SiteDataVO>(VO, dataList);
      return Response.success({
        data: result,
      });
    } catch (e) {
      return Response.error({ message: e });
    }
  }

  async addSiteService(DTO: any) {
    try {
      DTO = addTimeFields({
        delFlag: 0,
        views: 0,
        ...DTO,
      });
      await this.siteRepository.addSiteRepository(DTO);
      return Response.success({
        message: '新增成功',
      });
    } catch (e) {
      return Response.error({ message: e });
    }
  }

  async deleteSiteService() {}

  async updateSiteService() {}
}
